unit FormPrincipalCampoAplicacaoUnit;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls, Vcl.Buttons,
  Vcl.Grids, Vcl.DBGrids, JvExDBGrids, JvDBGrid, JvExComCtrls, JvComCtrls,
  Vcl.ExtCtrls, Data.FMTBcd, Data.SqlExpr, Datasnap.Provider, Data.DB,
  Datasnap.DBClient, System.Actions, Vcl.ActnList;

type
  TFormPrincipalCampoAplicacao = class(TForm)
    PanelBaixo: TPanel;
    Panel2: TPanel;
    JvPageControl: TJvPageControl;
    Panel1: TPanel;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet5: TTabSheet;
    LabelRef: TLabel;
    BitBtn7: TBitBtn;
    TabSheet6: TTabSheet;
    PageControl1: TPageControl;
    Inseticidas: TTabSheet;
    Fungicida: TTabSheet;
    Amendoim: TTabSheet;
    PageControl2: TPageControl;
    TabSheet7: TTabSheet;
    TabSheet8: TTabSheet;
    PageControl3: TPageControl;
    TabSheet9: TTabSheet;
    TabSheet10: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    EditLocalMirex: TEdit;
    EditQtdeAplicadaMirex: TEdit;
    Label3: TLabel;
    DateTimePickerAplicacaoMirex: TDateTimePicker;
    Label4: TLabel;
    DateTimePickerRetiradaMirex: TDateTimePicker;
    Label5: TLabel;
    BitBtnAdicionarMirex: TBitBtn;
    PageControl4: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet11: TTabSheet;
    JvDBGridFormicidaMirex: TJvDBGrid;
    Label6: TLabel;
    EditLocalMadepo: TEdit;
    EditQtdeAplicadaMadepo: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    DateTimePickerAplicacaoMadepo: TDateTimePicker;
    Label9: TLabel;
    DateTimePickerRetiradaMadepo: TDateTimePicker;
    Label10: TLabel;
    BitBtnAdicionarMadepo: TBitBtn;
    Label11: TLabel;
    EditLocalAllly: TEdit;
    Label12: TLabel;
    EditQtdeAplicadaAllly: TEdit;
    Label13: TLabel;
    DateTimePickerAplicacaoAllly: TDateTimePicker;
    Label14: TLabel;
    DateTimePickerRetiradaAllly: TDateTimePicker;
    Label15: TLabel;
    BitBtnAdicionarAllly: TBitBtn;
    JvDBGridHerbicidaAllly: TJvDBGrid;
    Label16: TLabel;
    EditLocalGladium: TEdit;
    Label17: TLabel;
    EditQtdeAplicadaGladium: TEdit;
    Label18: TLabel;
    DateTimePickerAplicacaoGladium: TDateTimePicker;
    Label19: TLabel;
    DateTimePickerRetiradaGladium: TDateTimePicker;
    Label20: TLabel;
    BitBtnAdicionarGladium: TBitBtn;
    JvDBGridHerbicidaGladium: TJvDBGrid;
    DataSourceForMirex: TDataSource;
    ClientDataSetForMirex: TClientDataSet;
    ClientDataSetForMirexID: TIntegerField;
    ClientDataSetForMirexLOCAL: TStringField;
    ClientDataSetForMirexQTDEAPLICADA: TStringField;
    ClientDataSetForMirexDATAAPLICACAO: TDateField;
    ClientDataSetForMirexDATARETIRADA: TDateField;
    ClientDataSetForMirexMARCADO: TBooleanField;
    ClientDataSetForMirexDATAREFERENCIA: TStringField;
    ActionList1: TActionList;
    Action1: TAction;
    BitBtn11: TBitBtn;
    DataSourceForMadepo: TDataSource;
    ClientDataSetForMadepo: TClientDataSet;
    ClientDataSetForMadepoID: TIntegerField;
    ClientDataSetForMadepoLOCAL: TStringField;
    ClientDataSetForMadepoQTDEAPLICADA: TStringField;
    ClientDataSetForMadepoDATAAPLICACAO: TDateField;
    ClientDataSetForMadepoDATARETIRADA: TDateField;
    ClientDataSetForMadepoMARCADO: TBooleanField;
    ClientDataSetForMadepoDATAREFERENCIA: TStringField;
    JvDBGridFormicidaMadepo: TJvDBGrid;
    ClientDataSetHerbAllly: TClientDataSet;
    DataSourceHerbAllly: TDataSource;
    ClientDataSetHerbAlllyID: TIntegerField;
    ClientDataSetHerbAlllyLOCAL: TStringField;
    ClientDataSetHerbAlllyQTDEAPLICADA: TStringField;
    ClientDataSetHerbAlllyDATAAPLICACAO: TDateField;
    ClientDataSetHerbAlllyDATARETIRADA: TDateField;
    ClientDataSetHerbAlllyMARCADO: TBooleanField;
    ClientDataSetHerbAlllyDATAREFERENCIA: TStringField;
    ClientDataSetHerbGladium: TClientDataSet;
    DataSourceHerbGladium: TDataSource;
    ClientDataSetHerbGladiumID: TIntegerField;
    ClientDataSetHerbGladiumLOCAL: TStringField;
    ClientDataSetHerbGladiumQTDEAPLICADA: TStringField;
    ClientDataSetHerbGladiumDATAAPLICACAO: TDateField;
    ClientDataSetHerbGladiumDATARETIRADA: TDateField;
    ClientDataSetHerbGladiumMARCADO: TBooleanField;
    ClientDataSetHerbGladiumDATAREFERENCIA: TStringField;
    ClientDataSetApInseticida: TClientDataSet;
    DataSourceApInseticida: TDataSource;
    ClientDataSetApInseticidaID: TIntegerField;
    ClientDataSetApInseticidaLOCAL: TStringField;
    ClientDataSetApInseticidaESPECIE: TStringField;
    ClientDataSetApInseticidaPRODUTOS: TStringField;
    ClientDataSetApInseticidaDATAPREVISAO: TDateField;
    ClientDataSetApInseticidaDATAAPLICACAO: TDateField;
    ClientDataSetApInseticidaDATAREFERENCIA: TStringField;
    ClientDataSetApInseticidaMARCADO: TBooleanField;
    ClientDataSetApInseticidaTT: TStringField;
    Label21: TLabel;
    Label22: TLabel;
    EditLocalApInseticida: TEdit;
    EditEspecieApInseticida: TEdit;
    Label23: TLabel;
    EditProdutosApInseticida: TEdit;
    Label26: TLabel;
    DateTimePickerPrevisaoApInseticida: TDateTimePicker;
    Label25: TLabel;
    DateTimePickerAplicacaoApInseticida: TDateTimePicker;
    Label24: TLabel;
    BitBtnAdicionarAPInseticida: TBitBtn;
    JvDBGridApInseticida: TJvDBGrid;
    Label27: TLabel;
    Label28: TLabel;
    EditLocalAcInseticda: TEdit;
    EditEspecieAcInseticda: TEdit;
    Label29: TLabel;
    EditProdutosAcInseticda: TEdit;
    Label30: TLabel;
    DateTimePickerPrevisaoAcInseticda: TDateTimePicker;
    Label31: TLabel;
    DateTimePickerAplicacaoAcInseticda: TDateTimePicker;
    Label32: TLabel;
    BitBtnAdicionarAcInseticda: TBitBtn;
    JvDBGridAcInseticda: TJvDBGrid;
    ClientDataSetAcInseticida: TClientDataSet;
    DataSourceAcInseticida: TDataSource;
    ClientDataSetAcInseticidaTT: TStringField;
    ClientDataSetAcInseticidaID: TIntegerField;
    ClientDataSetAcInseticidaLOCAL: TStringField;
    ClientDataSetAcInseticidaESPECIE: TStringField;
    ClientDataSetAcInseticidaPRODUTOS: TStringField;
    ClientDataSetAcInseticidaDATAPREVISAO: TDateField;
    ClientDataSetAcInseticidaDATAAPLICACAO: TDateField;
    ClientDataSetAcInseticidaDATAREFERENCIA: TStringField;
    ClientDataSetAcInseticidaMARCADO: TBooleanField;
    procedure FormShow(Sender: TObject);
    procedure BuscaID(id : string);
    procedure BitBtnAdicionarMirexClick(Sender: TObject);
    procedure Action1Execute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure PreencheGrid();
    procedure BitBtnAdicionarMadepoClick(Sender: TObject);
    procedure BitBtnAdicionarAlllyClick(Sender: TObject);
    procedure BitBtnAdicionarGladiumClick(Sender: TObject);
    procedure BitBtnAdicionarAPInseticidaClick(Sender: TObject);
    procedure BitBtnAdicionarAcInseticdaClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }

    strReferencia : String;
  end;

var
  FormPrincipalCampoAplicacao: TFormPrincipalCampoAplicacao;

implementation

{$R *.dfm}

uses DMDadosUnt;

procedure TFormPrincipalCampoAplicacao.Action1Execute(Sender: TObject);
begin
 close;
end;

procedure TFormPrincipalCampoAplicacao.BitBtnAdicionarAcInseticdaClick(
  Sender: TObject);
var
novocod : integer;
begin
  BuscaID('ID_AC_INSETICIDA');

  DMDados.cdsSelectAcInseticida.Open;
  DMDados.cdsSelectAcInseticida.Append;
  novocod := DMDados.cdsControleVALOR.AsInteger + 1;
  DMDados.cdsSelectAcInseticidaID_AC_INSETICIDA.AsInteger   := novocod;
  DMDados.cdsSelectAcInseticidaLOCAL.AsString               := EditLocalAcInseticda.Text;
  DMDados.cdsSelectAcInseticidaESPECIE.AsString             := EditEspecieAcInseticda.Text;
  DMDados.cdsSelectAcInseticidaPRODUTOS.AsString            := EditProdutosAcInseticda.Text;
  DMDados.cdsSelectAcInseticidaDATA_APLICACAO.AsDateTime    := DateTimePickerAplicacaoAcInseticda.Date;
  DMDados.cdsSelectAcInseticidaDATA_PREVISAO.AsDateTime     := DateTimePickerPrevisaoAcInseticda.Date;
  DMDados.cdsSelectAcInseticidaDATA_REFERENCIA.AsString     := strReferencia;
  DMDados.cdsSelectAcInseticidaTT.AsString                  := 'AC';

  DMDados.cdsSelectAcInseticida.ApplyUpdates(-1);
  DMDados.cdsSelectAcInseticida.Refresh;

  DMDados.cdsControle.Edit;
  DMDados.cdsControleVALOR.AsInteger := novocod;
  DMDados.cdsControle.ApplyUpdates(-1);

  PreencheGrid;
end;

procedure TFormPrincipalCampoAplicacao.BitBtnAdicionarAlllyClick(
  Sender: TObject);
var
novocod : integer;
begin
  BuscaID('ID_HERBICIDA_ALLLY');

  DMDados.cdsSelectHerbicidaAllly.Open;
  DMDados.cdsSelectHerbicidaAllly.Append;
  novocod := DMDados.cdsControleVALOR.AsInteger + 1;
  DMDados.cdsSelectHerbicidaAlllyID_HERBICIDA_ALLLY.AsInteger := novocod;
  DMDados.cdsSelectHerbicidaAlllyLOCAL.AsString               := EditLocalAllly.Text;
  DMDados.cdsSelectHerbicidaAlllyQTDE_APLICADA.AsString       := EditQtdeAplicadaAllly.Text;
  DMDados.cdsSelectHerbicidaAlllyDATA_APLICACAO.AsDateTime    := DateTimePickerAplicacaoAllly.Date;
  DMDados.cdsSelectHerbicidaAlllyDATA_RETIRADA.AsDateTime     := DateTimePickerRetiradaAllly.Date;
  DMDados.cdsSelectHerbicidaAlllyDATA_REFERENCIA.AsString     := strReferencia;

  DMDados.cdsSelectHerbicidaAllly.ApplyUpdates(-1);
  DMDados.cdsSelectHerbicidaAllly.Refresh;

  DMDados.cdsControle.Edit;
  DMDados.cdsControleVALOR.AsInteger := novocod;
  DMDados.cdsControle.ApplyUpdates(-1);

  PreencheGrid;
end;

procedure TFormPrincipalCampoAplicacao.BitBtnAdicionarAPInseticidaClick(
  Sender: TObject);
var
novocod : integer;
begin
  BuscaID('ID_AP_INSETICIDA');

  DMDados.cdsSelectAPInseticida.Open;
  DMDados.cdsSelectAPInseticida.Append;
  novocod := DMDados.cdsControleVALOR.AsInteger + 1;
  DMDados.cdsSelectAPInseticidaID_AP_INSETICIDA.AsInteger   := novocod;
  DMDados.cdsSelectAPInseticidaLOCAL.AsString               := EditLocalApInseticida.Text;
  DMDados.cdsSelectAPInseticidaESPECIE.AsString             := EditEspecieApInseticida.Text;
  DMDados.cdsSelectAPInseticidaPRODUTOS.AsString            := EditProdutosApInseticida.Text;
  DMDados.cdsSelectAPInseticidaDATA_APLICACAO.AsDateTime    := DateTimePickerAplicacaoApInseticida.Date;
  DMDados.cdsSelectAPInseticidaDATA_PREVISAO.AsDateTime     := DateTimePickerPrevisaoApInseticida.Date;
  DMDados.cdsSelectAPInseticidaDATA_REFERENCIA.AsString     := strReferencia;
  DMDados.cdsSelectAPInseticidaTT.AsString                  := 'AP';

  DMDados.cdsSelectAPInseticida.ApplyUpdates(-1);
  DMDados.cdsSelectAPInseticida.Refresh;

  DMDados.cdsControle.Edit;
  DMDados.cdsControleVALOR.AsInteger := novocod;
  DMDados.cdsControle.ApplyUpdates(-1);

  PreencheGrid;
end;

procedure TFormPrincipalCampoAplicacao.BitBtnAdicionarGladiumClick(
  Sender: TObject);
  var
    novocod : integer;
  begin
  BuscaID('ID_HERBICIDA_GLADIUM');

  DMDados.cdsSelectHerbicidaGladium.Open;
  DMDados.cdsSelectHerbicidaGladium.Append;
  novocod := DMDados.cdsControleVALOR.AsInteger + 1;
  DMDados.cdsSelectHerbicidaGladiumID_HERBICIDA_GLADIUM.AsInteger := novocod;
  DMDados.cdsSelectHerbicidaGladiumLOCAL.AsString               := EditLocalGladium.Text;
  DMDados.cdsSelectHerbicidaGladiumQTDE_APLICADA.AsString       := EditQtdeAplicadaGladium.Text;
  DMDados.cdsSelectHerbicidaGladiumDATA_APLICACAO.AsDateTime    := DateTimePickerAplicacaoGladium.Date;
  DMDados.cdsSelectHerbicidaGladiumDATA_RETIRADA.AsDateTime     := DateTimePickerRetiradaGladium.Date;
  DMDados.cdsSelectHerbicidaGladiumDATA_REFERENCIA.AsString     := strReferencia;

  DMDados.cdsSelectHerbicidaGladium.ApplyUpdates(-1);
  DMDados.cdsSelectHerbicidaGladium.Refresh;

  DMDados.cdsControle.Edit;
  DMDados.cdsControleVALOR.AsInteger := novocod;
  DMDados.cdsControle.ApplyUpdates(-1);

  PreencheGrid;
end;

procedure TFormPrincipalCampoAplicacao.BitBtnAdicionarMadepoClick(
  Sender: TObject);
var
novocod : integer;
begin
  BuscaID('ID_FORMICIDA_MADEPO');

  DMDados.cdsSelectFormicidamadepo.Open;
  DMDados.cdsSelectFormicidamadepo.Append;
  novocod := DMDados.cdsControleVALOR.AsInteger + 1;
  DMDados.cdsSelectFormicidamadepoID_FORMICIDA_madepo.AsInteger := novocod;
  DMDados.cdsSelectFormicidamadepoLOCAL.AsString               := EditLocalmadepo.Text;
  DMDados.cdsSelectFormicidamadepoQTDE_APLICADA.AsString       := EditQtdeAplicadamadepo.Text;
  DMDados.cdsSelectFormicidamadepoDATA_APLICACAO.AsDateTime    := DateTimePickerAplicacaomadepo.Date;
  DMDados.cdsSelectFormicidamadepoDATA_RETIRADA.AsDateTime     := DateTimePickerRetiradamadepo.Date;
  DMDados.cdsSelectFormicidamadepoDATA_REFERENCIA.AsString     := strReferencia;

  DMDados.cdsSelectFormicidamadepo.ApplyUpdates(-1);
  DMDados.cdsSelectFormicidamadepo.Refresh;

  DMDados.cdsControle.Edit;
  DMDados.cdsControleVALOR.AsInteger := novocod;
  DMDados.cdsControle.ApplyUpdates(-1);

  PreencheGrid;
end;

procedure TFormPrincipalCampoAplicacao.BitBtnAdicionarMirexClick(Sender: TObject);
var
novocod : integer;
begin
  BuscaID('ID_FORMICIDA_MIREX');

  DMDados.cdsSelectFormicidaMirex.Open;
  DMDados.cdsSelectFormicidaMirex.Append;
  novocod := DMDados.cdsControleVALOR.AsInteger + 1;
  DMDados.cdsSelectFormicidaMirexID_FORMICIDA_MIREX.AsInteger := novocod;
  DMDados.cdsSelectFormicidaMirexLOCAL.AsString               := EditLocalMirex.Text;
  DMDados.cdsSelectFormicidaMirexQTDE_APLICADA.AsString       := EditQtdeAplicadaMirex.Text;
  DMDados.cdsSelectFormicidaMirexDATA_APLICACAO.AsDateTime    := DateTimePickerAplicacaoMirex.Date;
  DMDados.cdsSelectFormicidaMirexDATA_RETIRADA.AsDateTime     := DateTimePickerRetiradaMirex.Date;
  DMDados.cdsSelectFormicidaMirexDATA_REFERENCIA.AsString     := strReferencia;

  DMDados.cdsSelectFormicidaMirex.ApplyUpdates(-1);
  DMDados.cdsSelectFormicidaMirex.Refresh;

  DMDados.cdsControle.Edit;
  DMDados.cdsControleVALOR.AsInteger := novocod;
  DMDados.cdsControle.ApplyUpdates(-1);

  PreencheGrid;

end;

procedure TFormPrincipalCampoAplicacao.BuscaID(id : string);
begin
  DMDados.cdsControle.Close;
  DMDados.cdsControle.Params[0].AsString := id;
  DMDados.cdsControle.Open;
end;

procedure TFormPrincipalCampoAplicacao.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  //AnimateWindow(Handle, 1000, AW_HIDE+AW_BLEND);
end;

procedure TFormPrincipalCampoAplicacao.FormShow(Sender: TObject);
begin
 LabelRef.Caption := strReferencia;

 DMDados.cdsSelectFormicidaMirex.Close;
 DMDados.cdsSelectFormicidaMirex.Params[0].AsString := strReferencia;
 DMDados.cdsSelectFormicidaMirex.Open;

 DMDados.cdsSelectFormicidaMadepo.Close;
 DMDados.cdsSelectFormicidaMadepo.Params[0].AsString := strReferencia;
 DMDados.cdsSelectFormicidaMadepo.Open;

 DMDados.cdsSelectHerbicidaAllly.Close;
 DMDados.cdsSelectHerbicidaAllly.Params[0].AsString := strReferencia;
 DMDados.cdsSelectHerbicidaAllly.Open;

 DMDados.cdsSelectHerbicidaGladium.Close;
 DMDados.cdsSelectHerbicidaGladium.Params[0].AsString := strReferencia;
 DMDados.cdsSelectHerbicidaGladium.Open;

 DMDados.cdsSelectAPInseticida.Close;
 DMDados.cdsSelectAPInseticida.Params[0].AsString := strReferencia;
 DMDados.cdsSelectAPInseticida.Open;

 DMDados.cdsSelectAcInseticida.Close;
 DMDados.cdsSelectAcInseticida.Params[0].AsString := strReferencia;
 DMDados.cdsSelectAcInseticida.Open;

 PreencheGrid;
end;

procedure TFormPrincipalCampoAplicacao.PreencheGrid;
begin


 {$Region' - Formicida Mirex - }
 JvDBGridFormicidaMirex.DataSource.DataSet.DisableControls;

 DataSourceForMirex.DataSet.First;
 DataSourceForMirex.DataSet.Edit;

 while not DataSourceForMirex.DataSet.Eof do
 begin

  DataSourceForMirex.DataSet.First;
  DataSourceForMirex.DataSet.Delete;

  DataSourceForMirex.DataSet.Next;
  if not DataSourceForMirex.DataSet.IsEmpty then
     DataSourceForMirex.DataSet.Delete;

 end;

 DataSourceForMirex.DataSet.First;

 DMDados.dsSelectFormicidaMirex.DataSet.First;

 while not DMDados.dsSelectFormicidaMirex.DataSet.Eof do
 begin

 ClientDataSetForMirex.Edit;
 ClientDataSetForMirex.Append;

 ClientDataSetForMirexID.Value              := DMDados.dsSelectFormicidaMirex.DataSet.FieldByName('ID_FORMICIDA_MIREX').AsInteger;
 ClientDataSetForMirexLOCAL.Value           := DMDados.dsSelectFormicidaMirex.DataSet.FieldByName('LOCAL').AsString;
 ClientDataSetForMirexQTDEAPLICADA.Value    := DMDados.dsSelectFormicidaMirex.DataSet.FieldByName('QTDE_APLICADA').AsString;
 ClientDataSetForMirexDATAAPLICACAO.Value   := DMDados.dsSelectFormicidaMirex.DataSet.FieldByName('DATA_APLICACAO').AsDateTime;
 ClientDataSetForMirexDATARETIRADA.Value    := DMDados.dsSelectFormicidaMirex.DataSet.FieldByName('DATA_RETIRADA').AsDateTime;
 ClientDataSetForMirexDATAREFERENCIA.Value  := DMDados.dsSelectFormicidaMirex.DataSet.FieldByName('DATA_REFERENCIA').AsString;
 ClientDataSetForMirexMARCADO.Value         := false;

 DMDados.dsSelectFormicidaMirex.DataSet.Next;

 end;

 DataSourceForMirex.DataSet.First;
 JvDBGridFormicidaMirex.DataSource.DataSet.EnableControls;
 {$EndRegion}

 {$Region' - Formicida Madepo - }
 JvDBGridFormicidamadepo.DataSource.DataSet.DisableControls;

 DataSourceFormadepo.DataSet.First;
 DataSourceFormadepo.DataSet.Edit;

 while not DataSourceFormadepo.DataSet.Eof do
 begin

  DataSourceFormadepo.DataSet.First;
  DataSourceFormadepo.DataSet.Delete;

  DataSourceFormadepo.DataSet.Next;
  if not DataSourceFormadepo.DataSet.IsEmpty then
     DataSourceFormadepo.DataSet.Delete;

 end;

 DataSourceFormadepo.DataSet.First;

 DMDados.dsSelectFormicidamadepo.DataSet.First;

 while not DMDados.dsSelectFormicidamadepo.DataSet.Eof do
 begin

 ClientDataSetFormadepo.Edit;
 ClientDataSetFormadepo.Append;

 ClientDataSetForMadepoID.Value              := DMDados.dsSelectFormicidamadepo.DataSet.FieldByName('ID_FORMICIDA_MADEPO').AsInteger;
 ClientDataSetFormadepoLOCAL.Value           := DMDados.dsSelectFormicidamadepo.DataSet.FieldByName('LOCAL').AsString;
 ClientDataSetFormadepoQTDEAPLICADA.Value    := DMDados.dsSelectFormicidamadepo.DataSet.FieldByName('QTDE_APLICADA').AsString;
 ClientDataSetFormadepoDATAAPLICACAO.Value   := DMDados.dsSelectFormicidamadepo.DataSet.FieldByName('DATA_APLICACAO').AsDateTime;
 ClientDataSetFormadepoDATARETIRADA.Value    := DMDados.dsSelectFormicidamadepo.DataSet.FieldByName('DATA_RETIRADA').AsDateTime;
 ClientDataSetFormadepoDATAREFERENCIA.Value  := DMDados.dsSelectFormicidamadepo.DataSet.FieldByName('DATA_REFERENCIA').AsString;
 ClientDataSetFormadepoMARCADO.Value         := false;

 DMDados.dsSelectFormicidamadepo.DataSet.Next;

 end;

 DataSourceFormadepo.DataSet.First;
 JvDBGridFormicidamadepo.DataSource.DataSet.EnableControls;
 {$EndRegion}

 {$Region' - Herbicida Allly - }
 JvDBGridHerbicidaAllly.DataSource.DataSet.DisableControls;

 DataSourceHerbAllly.DataSet.First;
 DataSourceHerbAllly.DataSet.Edit;

 while not DataSourceHerbAllly.DataSet.Eof do
 begin

  DataSourceHerbAllly.DataSet.First;
  DataSourceHerbAllly.DataSet.Delete;

  DataSourceHerbAllly.DataSet.Next;
  if not DataSourceHerbAllly.DataSet.IsEmpty then
     DataSourceHerbAllly.DataSet.Delete;

 end;

 DataSourceHerbAllly.DataSet.First;

 DMDados.dsSelectHerbicidaAllly.DataSet.First;

 while not DMDados.dsSelectHerbicidaAllly.DataSet.Eof do
 begin

 ClientDataSetHerbAllly.Edit;
 ClientDataSetHerbAllly.Append;

 ClientDataSetHerbAlllyID.Value              := DMDados.dsSelectHerbicidaAllly.DataSet.FieldByName('ID_HERBICIDA_ALLLY').AsInteger;
 ClientDataSetHerbAlllyLOCAL.Value           := DMDados.dsSelectHerbicidaAllly.DataSet.FieldByName('LOCAL').AsString;
 ClientDataSetHerbAlllyQTDEAPLICADA.Value    := DMDados.dsSelectHerbicidaAllly.DataSet.FieldByName('QTDE_APLICADA').AsString;
 ClientDataSetHerbAlllyDATAAPLICACAO.Value   := DMDados.dsSelectHerbicidaAllly.DataSet.FieldByName('DATA_APLICACAO').AsDateTime;
 ClientDataSetHerbAlllyDATARETIRADA.Value    := DMDados.dsSelectHerbicidaAllly.DataSet.FieldByName('DATA_RETIRADA').AsDateTime;
 ClientDataSetHerbAlllyDATAREFERENCIA.Value  := DMDados.dsSelectHerbicidaAllly.DataSet.FieldByName('DATA_REFERENCIA').AsString;
 ClientDataSetHerbAlllyMARCADO.Value         := false;

 DMDados.dsSelectHerbicidaAllly.DataSet.Next;

 end;

 DataSourceHerbAllly.DataSet.First;
 JvDBGridHerbicidaAllly.DataSource.DataSet.EnableControls;
 {$EndRegion}

 {$Region' - Herbicida Gladium - }
 JvDBGridHerbicidaGladium.DataSource.DataSet.DisableControls;

 DataSourceHerbGladium.DataSet.First;
 DataSourceHerbGladium.DataSet.Edit;

 while not DataSourceHerbGladium.DataSet.Eof do
 begin

  DataSourceHerbGladium.DataSet.First;
  DataSourceHerbGladium.DataSet.Delete;

  DataSourceHerbGladium.DataSet.Next;
  if not DataSourceHerbGladium.DataSet.IsEmpty then
     DataSourceHerbGladium.DataSet.Delete;

 end;

 DataSourceHerbGladium.DataSet.First;

 DMDados.dsSelectHerbicidaGladium.DataSet.First;

 while not DMDados.dsSelectHerbicidaGladium.DataSet.Eof do
 begin

 ClientDataSetHerbGladium.Edit;
 ClientDataSetHerbGladium.Append;

 ClientDataSetHerbGladiumID.Value              := DMDados.dsSelectHerbicidaGladium.DataSet.FieldByName('ID_HERBICIDA_GLADIUM').AsInteger;
 ClientDataSetHerbGladiumLOCAL.Value           := DMDados.dsSelectHerbicidaGladium.DataSet.FieldByName('LOCAL').AsString;
 ClientDataSetHerbGladiumQTDEAPLICADA.Value    := DMDados.dsSelectHerbicidaGladium.DataSet.FieldByName('QTDE_APLICADA').AsString;
 ClientDataSetHerbGladiumDATAAPLICACAO.Value   := DMDados.dsSelectHerbicidaGladium.DataSet.FieldByName('DATA_APLICACAO').AsDateTime;
 ClientDataSetHerbGladiumDATARETIRADA.Value    := DMDados.dsSelectHerbicidaGladium.DataSet.FieldByName('DATA_RETIRADA').AsDateTime;
 ClientDataSetHerbGladiumDATAREFERENCIA.Value  := DMDados.dsSelectHerbicidaGladium.DataSet.FieldByName('DATA_REFERENCIA').AsString;
 ClientDataSetHerbGladiumMARCADO.Value         := false;

 DMDados.dsSelectHerbicidaGladium.DataSet.Next;

 end;

 DataSourceHerbGladium.DataSet.First;
 JvDBGridHerbicidaGladium.DataSource.DataSet.EnableControls;
 {$EndRegion}

  {$Region' - AC Inseticida - }

 JvDBGridAcInseticda.DataSource.DataSet.DisableControls;

 DataSourceAcInseticida.DataSet.First;
 DataSourceAcInseticida.DataSet.Edit;

 while not DataSourceAcInseticida.DataSet.Eof do
 begin

  DataSourceAcInseticida.DataSet.First;
  DataSourceAcInseticida.DataSet.Delete;

  DataSourceAcInseticida.DataSet.Next;
  if not DataSourceAcInseticida.DataSet.IsEmpty then
     DataSourceAcInseticida.DataSet.Delete;

 end;

 DataSourceAcInseticida.DataSet.First;

 DMDados.dsSelectAcInseticida.DataSet.First;

 while not DMDados.dsSelectAcInseticida.DataSet.Eof do
 begin

 ClientDataSetAcInseticida.Edit;
 ClientDataSetAcInseticida.Append;

 ClientDataSetAcInseticidaID.Value              := DMDados.dsSelectAcInseticida.DataSet.FieldByName('ID_AC_INSETICIDA').AsInteger;
 ClientDataSetAcInseticidaLOCAL.Value           := DMDados.dsSelectAcInseticida.DataSet.FieldByName('LOCAL').AsString;
 ClientDataSetAcInseticidaESPECIE.Value         := DMDados.dsSelectAcInseticida.DataSet.FieldByName('ESPECIE').AsString;
 ClientDataSetAcInseticidaPRODUTOS.Value        := DMDados.dsSelectAcInseticida.DataSet.FieldByName('PRODUTOS').AsString;
 ClientDataSetAcInseticidaDATAAPLICACAO.Value   := DMDados.dsSelectAcInseticida.DataSet.FieldByName('DATA_APLICACAO').AsDateTime;
 ClientDataSetAcInseticidaDATAPREVISAO.Value    := DMDados.dsSelectAcInseticida.DataSet.FieldByName('DATA_PREVISAO').AsDateTime;
 ClientDataSetAcInseticidaDATAREFERENCIA.Value  := DMDados.dsSelectAcInseticida.DataSet.FieldByName('DATA_REFERENCIA').AsString;
 ClientDataSetAcInseticidaTT.Value              := 'AC';
 ClientDataSetAcInseticidaMARCADO.Value         := false;

 DMDados.dsSelectAcInseticida.DataSet.Next;

 end;

 DataSourceAcInseticida.DataSet.First;
 JvDBGridAcInseticda.DataSource.DataSet.EnableControls;
 {$EndRegion}


 {$Region' - AP Inseticida - }

 JvDBGridApInseticida.DataSource.DataSet.DisableControls;

 DataSourceApInseticida.DataSet.First;
 DataSourceApInseticida.DataSet.Edit;

 while not DataSourceApInseticida.DataSet.Eof do
 begin

  DataSourceApInseticida.DataSet.First;
  DataSourceApInseticida.DataSet.Delete;

  DataSourceApInseticida.DataSet.Next;
  if not DataSourceApInseticida.DataSet.IsEmpty then
     DataSourceApInseticida.DataSet.Delete;

 end;

 DataSourceApInseticida.DataSet.First;

 DMDados.dsSelectAPInseticida.DataSet.First;

 while not DMDados.dsSelectAPInseticida.DataSet.Eof do
 begin

 ClientDataSetApInseticida.Edit;
 ClientDataSetApInseticida.Append;

 ClientDataSetApInseticidaID.Value              := DMDados.dsSelectAPInseticida.DataSet.FieldByName('ID_AP_INSETICIDA').AsInteger;
 ClientDataSetApInseticidaLOCAL.Value           := DMDados.dsSelectAPInseticida.DataSet.FieldByName('LOCAL').AsString;
 ClientDataSetApInseticidaESPECIE.Value         := DMDados.dsSelectAPInseticida.DataSet.FieldByName('ESPECIE').AsString;
 ClientDataSetApInseticidaPRODUTOS.Value        := DMDados.dsSelectAPInseticida.DataSet.FieldByName('PRODUTOS').AsString;
 ClientDataSetApInseticidaDATAAPLICACAO.Value   := DMDados.dsSelectAPInseticida.DataSet.FieldByName('DATA_APLICACAO').AsDateTime;
 ClientDataSetApInseticidaDATAPREVISAO.Value    := DMDados.dsSelectAPInseticida.DataSet.FieldByName('DATA_PREVISAO').AsDateTime;
 ClientDataSetApInseticidaDATAREFERENCIA.Value  := DMDados.dsSelectAPInseticida.DataSet.FieldByName('DATA_REFERENCIA').AsString;
 ClientDataSetApInseticidaTT.Value              := 'AP';
 ClientDataSetApInseticidaMARCADO.Value         := false;

 DMDados.dsSelectAPInseticida.DataSet.Next;

 end;

 DataSourceApInseticida.DataSet.First;
 JvDBGridApInseticida.DataSource.DataSet.EnableControls;
 {$EndRegion}


 end;

end.
